﻿using System.Xml.Serialization;
using Alex.HydroDynLib.Enums;

namespace Alex.HydroDynLib.Measures
{
    [XmlRoot("Length")]
    public class Length : MeasureBase
    {
        #region Construct

        public Length()
        {
            value = 0;
        }

        public Length(double val)
        {
            value = val;
        }

        public Length(double val, Enums.Length mes)
        {
            value = 0;          //Иначе ошибка на следующей строке
            this[mes] = val;
        }

        public Length(Length len)
        {
            value = len.value;
        }

        #endregion

        public double this [Enums.Length index]        
        {
            get 
            {
                switch (index)
                {
                    case Enums.Length.Meter:
                        return value;
                    case Enums.Length.Kilometer:
                        return value/Constants.Kilometer;
                    case Enums.Length.NauticalMile:
                        return value/Constants.NMile;
                    default:
                        return 0;
                }
            }
            set 
            {
                switch (index)
                {
                    case Enums.Length.Meter:
                        this.value = value;
                        break;
                    case Enums.Length.Kilometer:
                        this.value = value*Constants.Kilometer;
                        break;
                    case Enums.Length.NauticalMile:
                        this.value = value*Constants.NMile;
                        break;
                    default:
                        break;
                }
            }
        }

        [XmlElement("Value")]
        public override double Value
        {
            get { return value; }
            set { this.value = value; }
        }

        public override string Measure
        {
            get { return "m"; }
        }

        public override string ToString()
        {
            return Value.ToString() + " " + Measure;
        }
    }
}
